{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import librosa\n",
    "import sounddevice as sd\n",
    "from simpledaw import SimpleDAW\n",
    "\n",
    "\n",
    "\n",
    "# synth_plugin = 'C:/VST/64bit/Sylenth1.dll'\n",
    "# simpledaw = SimpleDAW(plugin=synth_plugin)\n",
    "# simpledaw.load_midi(r\"B:\\muse_repo\\MIDI\\melody\\20220608_01.mid\")\n",
    "#\n",
    "# simpledaw.set_params(params)\n",
    "#\n",
    "# audio = librosa.to_mono(simpledaw.render(1))\n",
    "# sd.play(audio, samplerate=44100, blocking=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "import os\n",
    "import random\n",
    "from strophie_daw import DAW\n",
    "import time\n",
    "\n",
    "params = [0.5, 0.5, 0.5, 0.7310585379600525, 0.5169793963432312, 0.5, 0.7310585379600525, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.7310585379600525, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.5, 0.7310585379600525, 0.5, 0.7310585379600525, 0.5, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7270939350128174, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5000025033950806, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.7310585379600525, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.7310585379600525, 0.5, 0.5]\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "def get_files(directory, ext, with_dot=True):\n",
    "    path_list = []\n",
    "    for paths in [[os.path.join(dirpath, name) for name in filenames if\n",
    "                   name.endswith(('.' if with_dot else '') + ext)] for\n",
    "                  dirpath, dirnames, filenames in os.walk(directory)]:\n",
    "        path_list.extend(paths)\n",
    "    return path_list\n",
    "\n",
    "daw = DAW(backend='reaper', track_length=4, apply_immediately=True)\n",
    "\n",
    "daw.add_track()\n",
    "\n",
    "# simple_daw = Artear.utils.simpledaw.SimpleDAW('C:/VST/64bit/Sylenth1.dll')\n",
    "# fxp_files = get_files(r\"B:\\muse_repo\\Presets\\_Legacy\", 'fxp')\n",
    "# params = simple_daw.get_params(random.choice(fxp_files))\n",
    "\n",
    "mid_files = get_files(r\"B:\\muse_repo\\MIDI\\chord\", 'mid')\n",
    "\n",
    "daw.load_midi(random.choice(mid_files), track_id=-1)\n",
    "\n",
    "daw.add_fx(0, 'Sylenth1 (LennarDigital)', plugin_path='C:/VST/64bit/Sylenth1.dll')\n",
    "daw.set_fx_params(params, 0, 0)\n",
    "\n",
    "midi_data, fx_data = daw.to_numpy()\n",
    "print(midi_data.shape, fx_data.shape)\n",
    "# daw.apply_to_daw()\n",
    "# time.sleep(4)\n",
    "# daw.from_numpy(midi_data, fx_data)\n",
    "# daw.apply_to_daw()\n",
    "\n",
    "\n",
    "# daw.render()\n",
    "\n",
    "daw.close()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": true
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "ename": "OSError",
     "evalue": "[WinError 10038] 在一个非套接字上尝试了一个操作。",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mOSError\u001B[0m                                   Traceback (most recent call last)",
      "\u001B[1;32m~\\AppData\\Local\\Temp/ipykernel_13420/2498527356.py\u001B[0m in \u001B[0;36m<module>\u001B[1;34m\u001B[0m\n\u001B[1;32m----> 1\u001B[1;33m \u001B[0mdaw\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mset_fx_params\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mparams\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;33m-\u001B[0m\u001B[1;36m1\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;33m-\u001B[0m\u001B[1;36m1\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m",
      "\u001B[1;32mD:\\git_repos\\dmuse\\strophie_daw.py\u001B[0m in \u001B[0;36mset_fx_params\u001B[1;34m(self, params, track_id, fx_id)\u001B[0m\n\u001B[0;32m    107\u001B[0m         \u001B[1;32mif\u001B[0m \u001B[0mself\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mapply_immediately\u001B[0m\u001B[1;33m:\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m    108\u001B[0m             \u001B[1;32mif\u001B[0m \u001B[0misinstance\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mself\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mbackend\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mremote\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mReaperRemote\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m:\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[1;32m--> 109\u001B[1;33m                 \u001B[0mself\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mbackend\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mwake\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m\u001B[0;32m    110\u001B[0m                 \u001B[0mself\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mbackend\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mset_params\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mtrack_id\u001B[0m\u001B[1;33m=\u001B[0m\u001B[0mtrack_id\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mfx_id\u001B[0m\u001B[1;33m=\u001B[0m\u001B[0mfx_id\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mparams\u001B[0m\u001B[1;33m=\u001B[0m\u001B[0mparams\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m    111\u001B[0m             \u001B[1;32melif\u001B[0m \u001B[0misinstance\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mself\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mbackend\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mdawdmr\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mRenderEngine\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m:\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n",
      "\u001B[1;32mD:\\git_repos\\dmuse\\reaper_remote\\remote.py\u001B[0m in \u001B[0;36mwake\u001B[1;34m(self)\u001B[0m\n\u001B[0;32m     67\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m     68\u001B[0m     \u001B[1;32mdef\u001B[0m \u001B[0mwake\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mself\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m:\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[1;32m---> 69\u001B[1;33m         \u001B[0mself\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0msocket\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0msendto\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mOSCMessage\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\"/action/str\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\",i\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;36m41898\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;33m(\u001B[0m\u001B[1;34m'127.0.0.1'\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;36m8000\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m\u001B[0;32m     70\u001B[0m         \u001B[0mself\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0msocket\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0msendto\u001B[0m\u001B[1;33m(\u001B[0m\u001B[0mOSCMessage\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;34m\"/action/str\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;34m\",s\"\u001B[0m\u001B[1;33m,\u001B[0m \u001B[0mself\u001B[0m\u001B[1;33m.\u001B[0m\u001B[0mremote_control_id\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;33m(\u001B[0m\u001B[1;34m'127.0.0.1'\u001B[0m\u001B[1;33m,\u001B[0m \u001B[1;36m8000\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0;32m     71\u001B[0m \u001B[1;33m\u001B[0m\u001B[0m\n",
      "\u001B[1;31mOSError\u001B[0m: [WinError 10038] 在一个非套接字上尝试了一个操作。"
     ]
    }
   ],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}